package cn.stronglink.asset.module.assetmanage.cabinetgroup.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.plugins.Page;

import cn.stronglink.asset.model.CabinetGroup;
import cn.stronglink.asset.module.assetmanage.cabinetgroup.service.CabinetGroupService;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "cabinetGroup")
public class CabinetGroupController extends AbstractController {

	@Autowired
	private CabinetGroupService cabinetGroupService;

	/**
	 * 查询所有机柜组并分页
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "queryList")
	public ResponseEntity<ModelMap> queryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<CabinetGroup> page = (Page<CabinetGroup>) super.getPage(params);
		Page<CabinetGroup> data = cabinetGroupService.queryList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 根据机柜组Id查询机柜组明细
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {	
		CabinetGroup data =cabinetGroupService.qryById(id);
		return setSuccessModelMap(modelMap, data);
	}
	 
	/**
	 * 创建机柜组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param cabinetGroup
	 * @return
	 */
	@OperateLog(module = "机柜组管理",desc="添加机柜信息", type = OpType.ADD)
	@RequestMapping(value = "create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody CabinetGroup cabinetGroup) {
		cabinetGroupService.create(cabinetGroup);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 编辑机柜组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param cabinetGroup
	 * @return
	 */
	@OperateLog(module = "机柜组管理",desc="修改机柜组信息", type = OpType.UPDATE)
	@RequestMapping(value = "edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody CabinetGroup cabinetGroup) {
		cabinetGroupService.edit(cabinetGroup);
		return setSuccessModelMap(modelMap, null);
	}
	/**
	 * 删除机柜组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@OperateLog(module = "机柜组管理",desc="删除机柜", type = OpType.DEL)
	@RequestMapping(value = "remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		cabinetGroupService.remove(id);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 查询所有机柜组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "queryAllList")
	public ResponseEntity<ModelMap> queryCabinetGroupList(ModelMap modelMap, HttpServletRequest request,HttpServletResponse response) {	
		List<CabinetGroup> data = cabinetGroupService.queryAllList();
		return setSuccessModelMap(modelMap, data);
	}
	
	
}
